package com.baidu.foodrecipe.ui.fragment.joke

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.baidu.foodrecipe.data.repository.Repository
import com.baidu.foodrecipe.utils.APIKEY
import kotlinx.coroutines.launch

class JokeViewModel(application: Application) : AndroidViewModel(application) {
    private val repository = Repository(application)
    val text = MutableLiveData<String>()

    fun getJoke() {
        viewModelScope.launch {
            repository.getJokes(APIKEY)?.let { joke ->
                text.value = joke.text
            }
        }
    }
}